home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / play movie / completed lab / pmwindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  2.1 KB  |  90 lines

  1. /*
  2.     File:        PMWindow.c
  3.     
  4.     Contains:    QuickTime sample code
  5.  
  6.     Copyright:    © 2000 by Apple Computer, Inc. All rights reserved
  7.  
  8.  
  9. */
  10.  
  11. #include "PMWindow.h"
  12.  
  13. //////////
  14. //
  15. // QTFrame_CreateMovieWindow
  16. // Create a new window to display the movie in.
  17. //
  18. //////////
  19.  
  20. WindowReference CreateMovieWindow (void)
  21. {
  22.     WindowReference            myWindow = NULL;
  23.     WindowObject            myWindowObject = NULL;
  24.     
  25.     // create a new window to display the movie in
  26.     myWindow = NewCWindow(NULL,                // Window storage
  27.                           &gWindowRect,        // Bounds
  28.                           gWindowTitle,        // Window title
  29.                           false,            // Show window yes? no?
  30.                           kWindowFloatProc,    // WinProc ID
  31.                           (WindowPtr)-1L,   // Place in front
  32.                           true,                // Close box yes
  33.                           0);                // Reference constant            
  34.  
  35.     // create a new window object associated with the new window
  36.     QTFrame_CreateWindowObject(myWindow);
  37.  
  38.     return(myWindow);
  39. }
  40.  
  41. //////////
  42. //
  43. // QTFrame_SizeWindowToMovie
  44. // Set the window size to exactly fit the movie and controller (if visible).
  45. //
  46. //////////
  47.  
  48. void SizeWindowToMovie (WindowObject theWindowObject)
  49. {
  50.     Rect                    myMovieBounds;
  51.     Movie                    myMovie = NULL;
  52.  
  53. #if TARGET_OS_WIN32
  54.     gWeAreSizingWindow = true;
  55. #endif
  56.  
  57.     if (theWindowObject == NULL)
  58.         goto bail;
  59.     
  60.     myMovie = (**theWindowObject).fMovie;
  61.  
  62.     if (myMovie == NULL)
  63.         return;
  64.  
  65.     GetMovieBox(myMovie,            // Movie specifier
  66.                 &myMovieBounds);    // Movie bounds
  67.     
  68.     OffsetRect(&myMovieBounds, -myMovieBounds.left, -myMovieBounds.top);
  69.     
  70.     SetMovieBox(myMovie,            // Movie specifier
  71.                 &myMovieBounds);    // Movie bounds
  72.     
  73.     // make sure that the movie has a non-zero width;
  74.     // a zero height is okay (for example, with a music movie with no controller bar)
  75.     if (myMovieBounds.right - myMovieBounds.left == 0) {
  76.         myMovieBounds.left = 0;
  77.         myMovieBounds.right = QTFrame_GetWindowWidth((**theWindowObject).fWindow);
  78.     }
  79.  
  80.     SizeWindow(QTFrame_GetWindowFromWindowReference((**theWindowObject).fWindow),
  81.                                             myMovieBounds.right - myMovieBounds.left,
  82.                                             myMovieBounds.bottom - myMovieBounds.top,
  83.                                             true);
  84. bail:                                        
  85. #if TARGET_OS_WIN32
  86.     gWeAreSizingWindow = false;
  87. #endif
  88.  
  89.     return;
  90. }